package com.ujiuye.config;

import com.ujiuye.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author shiminghui
 * @date 2024/8/20 8:32
 * @description: TODO
 */
@Configuration
@Slf4j
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Autowired
    private LoginInterceptor loginInterceptor;

    //jwt校验
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册拦截器");
        //注册拦截器
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//拦截的路径
                .excludePathPatterns("/user/**");//放行的路径
        log.info("注册拦截器成功");
    }

    //跨域
/*    @Override
    protected void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/**")
                .allowedOrigins("http:localhost:8080") // 允许来自http://example.com的请求
                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的HTTP方法
                .allowedHeaders("*") // 允许任何头部
                .allowCredentials(true) // 允许发送Cookie
                .maxAge(3600); // 预检请求的缓存时间（秒）

    }*/
}
